package com.sdses.flink.gis;

import com.google.common.io.BaseEncoding;
import org.geotools.geometry.jts.WKBReader;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;

/**
 * @author jiwei
 * @description
 * @date 2024/12/24 15:05
 */
public class GisTest {
    public static void main(String[] args) {
        String hexewkb = "010100000000000000000024400000000000003440";
        try {
//            byte[] wkbBytes = hexStringToByteArray(hexewkb);

            byte[] wkbBytes = BaseEncoding.base16().lowerCase().decode(hexewkb);
            WKBReader reader = new WKBReader();
            Geometry geometry = reader.read(wkbBytes);
            System.out.println(geometry);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
    public static byte[] hexStringToByteArray(String s) {
        int len = s.length();
        byte[] data = new byte[len / 2];
        for (int i = 0; i < len; i += 2) {
            data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                    + Character.digit(s.charAt(i + 1), 16));
        }
        return data;
    }
}
